package cn.springstudio.springui;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.jaeger.library.StatusBarUtil;
import com.wangjie.rapidfloatingactionbutton.RapidFloatingActionHelper;

import cn.springstudio.springui.databinding.ActivityMainBinding;
import cn.springstudio.util.FragmentNavigation;

public class MainActivity extends AppCompatActivity implements FragmentNavigation.OnFragmentNavigationListener {

    RapidFloatingActionHelper rfabHelper;
    private ActivityMainBinding binding;
    private FragmentNavigation factory;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        StatusBarUtil.setLightMode(this);
        StatusBarUtil.setTransparentForDrawerLayout(this, binding.drawerLayout);

        binding.navigationMenu.setNavigationItemSelectedListener(item -> {
            binding.drawerLayout.closeDrawers();
            binding.navigationBottom.setSelectedItemId(item.getItemId());
            return true;
        });
        binding.navigationBottom.setOnItemSelectedListener(item -> {
            factory.navigationTo(item.getItemId());
            return true;
        });
        factory = FragmentNavigation.instance(getSupportFragmentManager(), R.id.container, this);
        factory.navigationTo(R.id.base);
    }

    @Override
    public Fragment onCreateFragment(int position) {
        if (position == R.id.base) {
            return BaseFragment.newInstance();
        } else if (position == R.id.extension) {
            return ExtensionFragment.newInstance();
        } else if (position == R.id.component) {
            return ComponentFragment.newInstance();
        } else if (position == R.id.my) {
            return SettingsFragment.newInstance();
        }
        return null;
    }
}